import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/sp_util.dart';

import '../../routes.dart';

class Splash extends StatefulWidget {
  @override
  _SplashState createState() => _SplashState();
}

class _SplashState extends State<Splash> {
  List<String> splashImages = ["splash_1.jpg", "splash_2.jpg", "splash_3.jpg"];
  SwiperController _swiperController = SwiperController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _updateSplash();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Swiper(
        loop: false,
        autoplay: false,
        controller: _swiperController,
        onTap: (index) {
          if (index == 2) {
            // urlPush(context, "yuntu://check_role");
            // Navigator.of(context).pushReplacementNamed("check_role");
            Navigator.of(context).pushReplacementNamed(RouteManager.adPage);
          }
        },
        itemBuilder: (BuildContext context, int index) {
          return Container(
            child: Image.asset(
              "assets/images/${splashImages[index]}",
              fit: BoxFit.cover,
            ),
          );
        },
        pagination: SwiperPagination(
            builder: DotSwiperPaginationBuilder(
          color: Colors.white,
          size: 5,
          activeSize: 5,
          activeColor: YTTheme.theme,
        )),
        itemCount: 3,
      ),
    );
  }

  _updateSplash() async {
    ///null加载 1跳过
    await SPUtil.setInt(RouteManager.splash, 1);
  }
}
